<template>
  <div class="menu-management-container">
    <el-row :gutter="24">

      <el-col >
        <el-card shadow="hover">
          <vab-query-form>
            <vab-query-form-top-panel :span="12">
              <el-button
                icon="el-icon-plus"
                type="primary"
                @click="handleEdit($event)"
              >
                添加
              </el-button>
            </vab-query-form-top-panel>
          </vab-query-form>
          <el-table
            v-loading="listLoading"
            :data="list"
            row-key="id"
            :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
          >
            <el-table-column
              label="菜单名称"
              prop="menuName"
              width="160"
              show-overflow-tooltip
            />
            <el-table-column label="图标"  width="100" show-overflow-tooltip>
              <template #default="{ row }">
                <vab-icon
                  v-if="row.metaIcon && row.metaIcon"
                  :icon="row.metaIcon"
                />
              </template>
            </el-table-column>
            <el-table-column label="排序" prop="orderNum" width="60" show-overflow-tooltip />
            <el-table-column label="路径" prop="path" show-overflow-tooltip />
            <el-table-column label="权限标识" prop="permissions" show-overflow-tooltip />
            <el-table-column
              label="组件路径"
              prop="component"
              show-overflow-tooltip
            />
            <el-table-column label="是否隐藏" show-overflow-tooltip>
              <template #default="{ row }">
                {{ row.alwaysShow === '1' ? '正常' : '隐藏' }}
              </template>
            </el-table-column>
            <el-table-column label="操作" show-overflow-tooltip width="185">
              <template #default="{ row }">
                <el-button type="primary" @click="handleEdit(row)">
                  <vab-icon icon="edit-2-line" />
                  编辑
                </el-button>
                <el-button type="danger" @click="handleDelete(row)">
                  <vab-icon icon="delete-bin-6-line" />
                  删除
                </el-button>
              </template>
            </el-table-column>
            <template #empty>
              <el-image
                class="vab-data-empty"
                :src="require('@/assets/empty_images/data_empty.png')"
              />
            </template>
          </el-table>
        </el-card>
      </el-col>
    </el-row>
    <edit ref="edit" :roleCode="roleCode" @fetch-data="fetchData" />
  </div>
</template>

<script>
  // import { getList } from '@/api/router'
  import { doDelete ,getListMenus } from '@/api/menuManagement'
  import Edit from './components/MenuManagementEdit'

  export default {
    name: 'MenuManagement',
    components: { Edit },
    data() {
      return {
        defaultProps: {
          children: 'children',
          label: 'label',
        },
        roleCode:26,
        list: [],
        listLoading: true,
      }
    },
    async created() {
      await this.fetchData(11)
    },
    methods: {
      handleEdit(row) {
        if (row.id) {
          this.$refs['edit'].showEdit(row)
        } else {
          this.$refs['edit'].showEdit()
        }
      },
      handleDelete(row) {
        if (row.id) {
          this.$baseConfirm('你确定要删除当前项吗', null, async () => {
            const { status ,message } = await doDelete(row.id)
            if (status != 200){
              this.$baseMessage(message, 'error', 'vab-hey-message-success')
            }else {
              this.$baseMessage(message, 'success', 'vab-hey-message-success')
            }
            await this.fetchData(11)
          })
        }
      },
      async fetchData() {
        this.listLoading = true
        const {
           data
        } = await getListMenus()
        this.list =data
        this.listLoading = false
      },
      handleNodeClick(param1,param2,param3) {
        this.roleCode = param1.id
        this.fetchData(param1.id)
      },
    },
  }
</script>

<style lang="scss" scoped>
  $base: '.menu-management';
  #{$base}-container {
    padding: 0 !important;
    background: $base-color-background !important;
  }

</style>
